<?php

namespace app\admin\model\user;

use think\Model;

class User extends Model
{
    // 表名
    protected $name = 'user_user';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'sex_text',
        'islook_text',
        'approve_status_text'
    ];

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }
    
    public function getSexList()
    {
        return ['1' => __('Sex 1'),'2' => __('Sex 2')];
    }     

    public function getIslookList()
    {
        return ['0' => __('Islook 0'),'1' => __('Islook 1')];
    }     

    public function getApproveStatusList()
    {
        return ['0' => __('Approve_status 0'),'1' => __('Approve_status 1'),'2' => __('Approve_status 2')];
    }     


    public function getSexTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIslookTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['islook']) ? $data['islook'] : '');
        $list = $this->getIslookList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getApproveStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['approve_status']) ? $data['approve_status'] : '');
        $list = $this->getApproveStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function attention()
    {
        return $this->hasMany('app\admin\model\user\attention\Suzerain', 'id','attention_id')->
        field('attention_id');
    }

    public function bbsreply()
    {
        return $this->hasMany('app\admin\model\bbs\Reply', 'id','user_id')->
        field('id');
    }

    public function bbscontent()
    {
        return $this->hasMany('app\admin\model\bbs\Contents', 'id','user_id')->
        field('id');
    }




}
